package com.wfm.niuke;

public class LongestPalindrome5 {
    public String longestPalindrome(String s) {
        if(s.length()==1) return s;
        String res = "";
        int max = 0;
        for(int i = 0;i<s.length()-1;i++){
            for(int j = i+1;j<s.length();j++){
                String sub = s.substring(i,j+1);
                if(isH(sub)){
                    if(sub.length()>max){
                        res = sub;
                        max = sub.length();
                    }
                }
            }
        }
        return res;
    }
    public boolean isH(String s){
        int i = 0;
        int j = s.length()-1;
        while(i<j){
            if(s.charAt(i)==s.charAt(j)){
                i++;
                j--;
            }else{
                return false;
            }
        }
        return true;
    }
}
